package com.github.catvod.spider.merge;

import com.github.catvod.spider.merge.B;
import java.util.Arrays;

/* loaded from: classes.dex */
final class fd {
    static final int[] V0 = {8364, 129, 8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 141, 381, 143, 144, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 157, 382, 376};
    private static final char[] h;
    private final UF j;
    private B oC;
    B.j oq;
    private final J5 q;
    private String y;
    private xb I = xb.h;
    private boolean BQ = false;
    private String W = null;
    private StringBuilder u = new StringBuilder(1024);
    StringBuilder Qy = new StringBuilder(1024);
    B.x F8 = new B.x();
    B.qM t = new B.qM();
    B.HA n = new B.HA();
    B.c iU = new B.c();
    B.d i4 = new B.d();
    private final int[] PD = new int[1];
    private final int[] j5 = new int[2];

    static {
        char[] cArr = {'\t', '\n', '\r', '\f', ' ', '<', '&'};
        h = cArr;
        Arrays.sort(cArr);
    }

    fd(UF uf, J5 j5) {
        this.j = uf;
        this.q = j5;
    }

    private void j(String str) {
        if (this.q.h()) {
            this.q.add(new lA(this.j.V(), "Invalid character reference: %s", str));
        }
    }

    void BQ() {
        this.iU.t();
    }

    void F8(StringBuilder sb) {
        if (this.W == null) {
            this.W = sb.toString();
            return;
        }
        if (this.u.length() == 0) {
            this.u.append(this.W);
        }
        this.u.append((CharSequence) sb);
    }

    void GM(xb xbVar) {
        if (this.q.h()) {
            this.q.add(new lA(this.j.V(), "Unexpected character '%s' in input state [%s]", Character.valueOf(this.j.GM()), xbVar));
        }
    }

    void I() {
        this.i4.t();
        this.i4.q = true;
    }

    void PD(xb xbVar) {
        if (this.q.h()) {
            this.q.add(new lA(this.j.V(), "Unexpectedly reached end of file (EOF) in input state [%s]", xbVar));
        }
    }

    boolean PU() {
        return this.y != null && this.oq.C4().equalsIgnoreCase(this.y);
    }

    void Qy(char c) {
        if (this.W == null) {
            this.W = String.valueOf(c);
            return;
        }
        if (this.u.length() == 0) {
            this.u.append(this.W);
        }
        this.u.append(c);
    }

    String V0() {
        return this.y;
    }

    B.j W(boolean z) {
        B.j t = z ? this.F8.t() : this.t.t();
        this.oq = t;
        return t;
    }

    void h(xb xbVar) {
        this.j.h();
        this.I = xbVar;
    }

    void i4() {
        t(this.iU);
    }

    void iU() {
        t(this.i4);
    }

    void j5(String str) {
        if (this.q.h()) {
            this.q.add(new lA(this.j.V(), str));
        }
    }

    void n(int[] iArr) {
        oq(new String(iArr, 0, iArr.length));
    }

    void oC() {
        this.i4.t();
    }

    void oq(String str) {
        if (this.W == null) {
            this.W = str;
            return;
        }
        if (this.u.length() == 0) {
            this.u.append(this.W);
        }
        this.u.append(str);
    }

    int[] q(Character ch, boolean z) {
        int i;
        if (this.j.PU()) {
            return null;
        }
        if ((ch != null && ch.charValue() == this.j.GM()) || this.j.f(h)) {
            return null;
        }
        int[] iArr = this.PD;
        this.j.w4();
        if (this.j.LW("#")) {
            boolean Og = this.j.Og("X");
            UF uf = this.j;
            String u = Og ? uf.u() : uf.W();
            if (u.length() == 0) {
                j("numeric reference with no numerals");
                this.j.z();
                return null;
            }
            this.j.H9();
            if (!this.j.LW(";")) {
                j("missing semicolon");
            }
            try {
                i = Integer.valueOf(u, Og ? 16 : 10).intValue();
            } catch (NumberFormatException unused) {
                i = -1;
            }
            if (i == -1 || ((i >= 55296 && i <= 57343) || i > 1114111)) {
                j("character outside of valid range");
                iArr[0] = 65533;
            } else {
                if (i >= 128) {
                    int[] iArr2 = V0;
                    if (i < iArr2.length + 128) {
                        j("character is not a valid unicode code point");
                        i = iArr2[i - 128];
                    }
                }
                iArr[0] = i;
            }
            return iArr;
        }
        String oq = this.j.oq();
        boolean R = this.j.R(';');
        if (!(XR.oC(oq) || (XR.BQ(oq) && R))) {
            this.j.z();
            if (R) {
                j("invalid named reference");
            }
            return null;
        }
        if (z && (this.j.nf() || this.j.Ig() || this.j.C4('=', '-', '_'))) {
            this.j.z();
            return null;
        }
        this.j.H9();
        if (!this.j.LW(";")) {
            j("missing semicolon");
        }
        int q = XR.q(oq, this.j5);
        if (q == 1) {
            iArr[0] = this.j5[0];
            return iArr;
        }
        if (q == 2) {
            return this.j5;
        }
        R2.h("Unexpected characters returned for " + oq);
        return this.j5;
    }

    void t(B b) {
        R2.V0(this.BQ);
        this.oC = b;
        this.BQ = true;
        B.i iVar = b.h;
        if (iVar == B.i.StartTag) {
            this.y = ((B.x) b).V0;
        } else if (iVar == B.i.EndTag && ((B.qM) b).R()) {
            j5("Attributes incorrectly present on end tag");
        }
    }

    void u() {
        B.n(this.Qy);
    }

    void w4(xb xbVar) {
        this.I = xbVar;
    }

    void y() {
        this.oq.LW();
        t(this.oq);
    }

    B yx() {
        while (!this.BQ) {
            this.I.u(this, this.j);
        }
        StringBuilder sb = this.u;
        if (sb.length() != 0) {
            String sb2 = sb.toString();
            sb.delete(0, sb.length());
            this.W = null;
            return this.n.i4(sb2);
        }
        String str = this.W;
        if (str == null) {
            this.BQ = false;
            return this.oC;
        }
        B.HA i4 = this.n.i4(str);
        this.W = null;
        return i4;
    }
}
